import {CHANGE_INPUT, ADD_ITEM, DELETE_ITEM, GET_LIST}  from './actionTypes'
import axios from 'axios'
import store from './index';

export const changeInputAction = (value)=>({
    type:CHANGE_INPUT,
    value
})

export const addItemAction = ()=>({
    type:ADD_ITEM
})

export const deleteItemAction = (index)=>({
    type:DELETE_ITEM,
    index
})

export const getListAction  = (data)=>({
    type:GET_LIST,
    data
})

export const getTodoList = () =>{
    return ()=>{
        axios.get('https://www.easy-mock.com/mock/5bda6056ac00753b8c22005f/example/todolist').then((res)=>{
            const data = res.data
            const action = getListAction(data)
            store.dispatch(action)
        })
    }
}